home *** CD-ROM | disk | FTP | other *** search
/ The Complete Utilities To…ka 501 Killer Utilities! / 501 Killer Utilities! (Macworld July 1995).cdr / Programming / Little Smalltalk v3.1.4 / C Source / Sources / CTextPane.cp < prev    next >
Encoding:
Text File  |  1995-01-31  |  5.5 KB  |  185 lines  |  [TEXT/KAHL]

  1. //=============================================================================
  2. //    Little Smalltalk, version 3
  3. //    Written by Tim Budd, Oregon State University, July 1988
  4. //
  5. //    Symantec Think Class Library interface code 
  6. //        ©Julian Barkway, April 1994, all rights reserved.
  7. //
  8. //    CTextPane.cp
  9. //    ------------
  10. //    This class implements a text-only pane.
  11. //=============================================================================
  12.  
  13. #include <string.h>
  14. #include "CTextPane.h"
  15. #include "Commands.h"
  16. #include "CLStDoc.h"
  17. #include "CLStWindow.h"
  18. #include "CBartender.h"
  19. #include "CLStApp.h"
  20. #include "Constants.h"
  21. #include <Global.h>
  22. #include "TCLUtilities.h"
  23.  
  24. extern    CLStApp        *gSmalltalk;
  25. extern    CBartender    *gBartender;
  26. extern     EventRecord  gLastMouseUp;
  27. extern     CBureaucrat    *gGopher;    
  28.  
  29. #define DOC_DIRTY    ((CDocument *)itsSupervisor)->dirty
  30.  
  31. //={OVERRIDE}==================================================================
  32. // Initialise a shiny new text pane object.
  33. //=============================================================================
  34. void CTextPane::ITextPane (CView *encl, CBureaucrat *super, 
  35.                             SizingOption hSizing, SizingOption vSizing,
  36.                             short lineLength)
  37. {
  38.     Rect    margin = {4, 4, 0, 0};
  39.     
  40.     IEditText      (encl, super, 1, 1, 0, 0, hSizing, vSizing, 2000);
  41.     FitToEnclosure (TRUE, TRUE);
  42.     ResizeFrame    (&margin);
  43. }
  44.  
  45.  
  46. //={OVERRIDE}==================================================================
  47. // Stop a click selecting text when it is combined with the option key.
  48. //=============================================================================
  49. void CTextPane::DoClick (Point hitPt, short modifierKeys, long when)
  50. {     
  51.     if (modifierKeys & optionKey)
  52.         return;
  53.  
  54.     inherited::DoClick (hitPt, modifierKeys, when);        
  55. }
  56.  
  57.  
  58. //={OVERRIDE}==================================================================
  59. // Handle menu dimming for cut'n'paste and ensure TCL commands aren't sent to
  60. // Smalltalk.
  61. //=============================================================================
  62. void CTextPane::DoCommand (long aCmd)
  63. {
  64.     if (aCmd == cmdPaste || aCmd == cmdCut)
  65.         if (! DOC_DIRTY) {
  66.             DOC_DIRTY = TRUE;
  67.             gBartender->EnableCmd (cmdSave);
  68.             gBartender->EnableCmd (cmdSaveAs);
  69.         }
  70.  
  71.     gSmalltalk->smalltalkCmd = FALSE;
  72.     inherited::DoCommand (aCmd);
  73.     if (! gSmalltalk->smalltalkCmd)
  74.          gSmalltalk->lastEvent.what = 0;
  75. }
  76.  
  77.  
  78. //={OVERRIDE}==================================================================
  79. // Ensure doc is set to be saved when an alphanumeric key has been pressed
  80. //=============================================================================
  81. void CTextPane::DoKeyDown (char ch, Byte keyCde, EventRecord *event)
  82. {
  83.     inherited::DoKeyDown (ch, keyCde, event);
  84.  
  85.     switch (keyCde) {
  86.         case KeyHome:
  87.         case KeyEnd:
  88.         case KeyPageUp:
  89.         case KeyPageDown:
  90.             break;
  91.         default: 
  92.             if (! DOC_DIRTY) {
  93.                 DOC_DIRTY = TRUE;
  94.                 gBartender->EnableCmd (cmdSave);
  95.                 gBartender->EnableCmd (cmdSaveAs);
  96.             }
  97.             break;
  98.     }
  99. }
  100.  
  101.  
  102. //={OVERRIDE}==================================================================
  103. // Handle auto repeat
  104. //=============================================================================
  105. void CTextPane::DoAutoKey (char ch, Byte keyCde, EventRecord *event)
  106. {
  107.     inherited::DoAutoKey (ch, keyCde, event);
  108.  
  109.     switch (keyCde) {
  110.         case KeyHome:
  111.         case KeyEnd:
  112.         case KeyPageUp:
  113.         case KeyPageDown:
  114.             break;
  115.         default:  
  116.             if (! DOC_DIRTY) {
  117.                 DOC_DIRTY = TRUE;
  118.                 gBartender->EnableCmd (cmdSave);
  119.                 gBartender->EnableCmd (cmdSaveAs);
  120.             }
  121.             break;
  122.     }
  123. }
  124.  
  125.  
  126. //={OVERRIDE}==================================================================
  127. // Ensure correct action taken if new insertion will take TE to >32k.
  128. //=============================================================================
  129. void CTextPane::CheckInsertion (long insertLen, Boolean useSelection)
  130. {
  131.     long        newLen, growSize;
  132.     short        ln, svSelStart, svSelEnd, newSelEnd;
  133.     Handle        hdl;
  134.     
  135.     newLen = (**macTE).teLength + insertLen;    
  136.     if (useSelection)
  137.         newLen -= (**macTE).selEnd - (**macTE).selStart;
  138.     
  139.     if (newLen > kMaxTELength) {
  140.         svSelStart = (**macTE).selStart;
  141.         svSelEnd   = (**macTE).selEnd;
  142.         newSelEnd  = insertLen;
  143.         ln = FindLine (newSelEnd);    // Ensure we're deleting a full line
  144.         newSelEnd = (**macTE).lineStarts [ln + 1];
  145.         SetSelection (0, newSelEnd, FALSE);
  146.         TEDelete (macTE);
  147.         SetSelection (svSelStart, svSelEnd, FALSE);
  148.     }
  149. // Either delete enough from the top to make the insertion fit or post a recoverable 
  150. // error, depending on the parameters for this pane. At the moment, will always delete
  151. // from top. Shouldn't be editing big files in Little Smalltalk anyway....
  152.  
  153. //***Failure (paramErr, excExceedTELimit);    // Don't fail for now
  154.         
  155.     growSize = newLen - (**macTE).teLength;            // check for available memory
  156.     if (growSize > 0) {
  157.         hdl = NewHandleCanFail (growSize);
  158.         FailNIL      (hdl);
  159.         DisposHandle (hdl);
  160.     }
  161. }
  162.  
  163.  
  164. //=============================================================================
  165. // Replace the current contents of the text pane with theText.
  166. //=============================================================================
  167. void CTextPane::ReplaceContents (char *theText)
  168. {
  169.     Prepare     ();
  170.     TESetSelect    (0L, 32767L, macTE);
  171.     TEDelete    (macTE);
  172.     TEInsert    (theText, (long)strlen (theText), macTE);
  173. }
  174.  
  175.  
  176. //=============================================================================
  177. // Completely delete the current contents of the text pane.
  178. //=============================================================================
  179. void CTextPane::DeleteContents (void)
  180. {
  181.     Prepare     ();
  182.     TESetSelect    (0L, 32767L, macTE);
  183.     TEDelete    (macTE);
  184. }
  185.